package com.ruoyi.elasticsearch.service.impl;

import com.ruoyi.elasticsearch.dao.ArticleRepository;
import com.ruoyi.elasticsearch.entity.Article;
import com.ruoyi.elasticsearch.service.ArticleService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @description: 业务方法 实现
 * @author: liyang
 * @date: 2025/7/21 15:36
 **/
@Service
@RequiredArgsConstructor
public class ArticleServiceImpl implements ArticleService {

    private final ArticleRepository articleRepository;

    @Override
    public Article save(Article article) {
        articleRepository.save(article);
        return article;
    }

    @Override
    public Optional<Article> findById(String id) {
        return articleRepository.findById(id);
    }

    @Override
    public Iterable<Article> findAll() {
        return articleRepository.findAll();
    }

    @Override
    public void deleteById(String id) {
        articleRepository.deleteById(id);
    }

    @Override
    public List<Article> searchByTitle(String keyword) {
        return articleRepository.findByTitleContaining(keyword);
    }
}
